package priv.yiyuan.example.composite.file;

import java.util.List;

/**
 * 文档组件抽象类
 * <p>
 * 组合模式-组件
 * 责任链模式-处理者接口
 *
 * @author YiYuan
 * @data 2025/8/29
 * @apoNote
 */
public abstract class DocumentComponent {

    protected String name;

    protected DocumentComponent parent;

    public DocumentComponent(String name) {
        this.name = name;
    }

    public void setParent(DocumentComponent parent) {
        this.parent = parent;
    }

    public DocumentComponent getParent() {
        return parent;
    }

    public void add(DocumentComponent component) {
        throw new UnsupportedOperationException();
    }

    public void remove(DocumentComponent component) {
        throw new UnsupportedOperationException();
    }

    public List<DocumentComponent> getChildren() {
        throw new UnsupportedOperationException();
    }

    public void display() {
        throw new UnsupportedOperationException();
    }

    /**
     * 责任链模式方法 - 检查权限
     */
    public boolean checkPermission(String user) {
        if (parent != null) {
            return parent.checkPermission(user);
        }

        return true;
    }
}

